package com.hz.common.freemarker;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.RandomAccessFile;

/**
 * 
 * @author malik
 * @version 2011-3-10 下午10:49:41
 */
public class EditFile {

	/**
     * 写入TXT，覆盖原内容
     * @param content
     * @param fileName
     * @return
     * @throws Exception
     */
    public static boolean writeTxtFile(String content,String fileName)throws Exception{
    	File file = new File(fileName);
        boolean flag=false;
        FileOutputStream fileOutputStream=null;
        try {
            fileOutputStream = new FileOutputStream(file);
            fileOutputStream.write(content.getBytes("utf-8"));
            fileOutputStream.close();
            flag=true;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return flag;
    }
	
	public static String readString(String filePath){
		String str="";
		File file=new File(filePath);
		try {
		    FileInputStream in=new FileInputStream(file);
		    // size  为字串的长度 ，这里一次性读完
		    int size=in.available();
		    byte[] buffer=new byte[size];
		    in.read(buffer);
		    in.close();
		    str=new String(buffer,"utf-8");
		} catch (IOException e) {
		    return null;
		}
		return str;
	}

}